package com.example.makerspace.controller;


import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody;

@RestController
public class GPTController {
    @GetMapping(value = "/stream", produces = MediaType.TEXT_PLAIN_VALUE)
    public StreamingResponseBody streamData() {
        return outputStream -> {
            // 在这里实现数据的流式写入到 outputStream
            for (int i = 0; i < 10000; i++) {
                outputStream.write("Hello, ".getBytes());
            }
            outputStream.write("Hello, ".getBytes());
            outputStream.write("world!".getBytes());
            // 可以写入更多数据...
            outputStream.flush();
        };
    }
}
